from collections.abc import Iterable
g = (x for x in range(2,10)) # 2-9
for x in g:
    print("x: ",x)

# g是一个generator
#打印g
print(isinstance(g ,(Iterable))) # 是可迭代对象，可以使用for迭代

def fib(max):
    n = 0
    a = 0
    b = 1
    while n <max:
        print(b)
        b = a+b
        a = b
        n+=1
    return "done"

# 带有yield的函数的返回值是一个generator对象
def fib2(max):
    n = 0
    a = 0
    b = 1
    while n <max:
        yield b
        b = a+b
        a = b
        n+=1
    return "done"


g = fib2(4)

def odd():
    # print('step 1')
    yield 1
    # print('step 2')
    yield(3)
    # print('step 3')
    yield(5)

o = odd()
print(next(o))
print(next(o))
print(next(o))
